package com.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sys.mapper.DictionaryMapper;
import com.sys.model.Dictionary;
import com.sys.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * Created by robin on 2016/8/17.
 * 数据字典
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryMapper mapper;

    @Override
    public boolean insert(Dictionary dictionary) {
        mapper.insertSelective(dictionary);
        return true;
    }

    @Override
    public boolean delete(String id) {
        mapper.deleteByPrimaryKey(id);
        return true;
    }

    @Override
    public boolean update(Dictionary dictionary) {
        mapper.updateByPrimaryKeySelective(dictionary);
        return true;
    }

    @Override
    public Dictionary selectById(String id) {
        return mapper.selectByPrimaryKey(id);
    }

    /**
     * 条件查询
     * @param map      参数 关键字key
     * @param pageNum  页码
     * @param pageSize 页面大小
     * @return 结果
     */
    @Override
    public PageInfo<Dictionary> search(Map map, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Dictionary> list= mapper.search(map);
        return new PageInfo<Dictionary>(list);
    }
}
